//
//  QTQualityListViewController.m
//  qdqts
//
//  Created by jonn on 14-7-7.
//  Copyright (c) 2014年 seas.cheng. All rights reserved.
//

#import "QTQualityListViewController.h"
#import "QTQualityInfoViewController.h"
#import "SVTopScrollView.h"
#import "QTQualityInfoViewController.h"
#import "QTClient.h"

@interface QTQualityListViewController ()

@end

@implementation QTQualityListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.navigationItem.title=@"监管信息";
    
//    UIImageView *topShadowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 200, 320, 5)];
//    [topShadowImageView setImage:[UIImage imageNamed:@"top_background_shadow.png"]];
//    [self.view addSubview:topShadowImageView];
    [self.failure setHidden:YES];
    [self.refresh startAnimating];
    
    [[QSClient instance] searchWithCategory:@"flag=1" completionBlock:^(QTSearchCategory *SearchCategory, NSError *error){
        _category=[[NSMutableArray alloc]initWithArray:SearchCategory.classifications];
        if (error) {
//            self.failure.text=@"无法连接服务器，请检查网络";
//            [self.failure setHidden:NO];
//            [self.refresh stopAnimating];
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示"
                                                          message:[NSString stringWithFormat:@"无法连接服务器，请稍后在试",nil]
                                                         delegate:self
                                                cancelButtonTitle:@"确定"
                                                otherButtonTitles:nil, nil];
            [alert show];
        }
        else if ([_category count] == 0) {
            NSLog(@"could not load the product");
            [self.failure setHidden:NO];
            [self.refresh stopAnimating];
        }
        else
        {
            [self.failure setHidden:YES];
            [self.refresh stopAnimating];
            SVTopScrollView *topScrollView = [[SVTopScrollView alloc] initWithFrame:CGRectMake(0, NAVBAR_HEIGHT, SCREEN_WIDTH, 44)];
            //SVRootScrollView *rootScrollView = [SVRootScrollView shareInstance];
            QTQualityInfoViewController *rootScrollView=[QTQualityInfoViewController shareInstance];
            
            NSMutableArray *tmpArray_name = [[NSMutableArray alloc] init];
            [tmpArray_name addObject:@"全部"];
            for (int i=0; i<[_category count]; i++) {
                [tmpArray_name addObject:(id)(((Classifications *)[_category objectAtIndex:i]).productTypeName)];
            }
            
            NSMutableArray *tmpArray_puid = [[NSMutableArray alloc] init];
            [tmpArray_puid addObject:@""];
            for (int i=0; i<[_category count]; i++) {
                [tmpArray_puid addObject:(id)(((Classifications *)[_category objectAtIndex:i]).puid)];
            }
            
            topScrollView.nameArray = tmpArray_name;
            topScrollView.puidArray = tmpArray_puid;
            
            [rootScrollView setValue:[tmpArray_puid objectAtIndex:0]];
            [self.view addSubview:topScrollView];
            [self.view addSubview:rootScrollView.view];
            [self.view sendSubviewToBack:rootScrollView.view];
            [self addChildViewController:rootScrollView];
            
            [topScrollView initWithNameButtons];

        }
    }];


    // Do any additional setup after loading the view from its nib.
}





- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
